#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 2e5 + 10, INF = 0x3f3f3f3f;

int n;
pair<int, int> a[N];
set<int> g[N];
int v[N], st[N], tt;

void solve()
{
    cin >> n;
    for (int i = 1;i <= n;i++) {
        cin >> a[i].first >> a[i].second;
        g[a[i].first].insert(i);g[a[i].second].insert(i);
    }

    int ans = 0;
    queue<int> q;
    q.push(0);v[0] = 1;
    while (!q.empty()) {
        int x = q.front();q.pop();
        ans++;
        for (int y : g[x])
            if ((v[a[y].first] || v[a[y].second]) && v[y] == 0) {
                v[y] = 1;
                q.push(y);
            }
    }

    cout << ans - 1 << '\n';
}


signed main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}